﻿using Library.Common.Model;
using Microsoft.AspNetCore.Mvc;
using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.Department;
using Synthesize.BaseSet.ServiceInterface.Query.Authority;
using Synthesize.BaseSet.ServiceInterface.UseCase.Authority;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SMS.WebApi.Areas.BaseSet.Controllers
{
    /// <summary>
    /// 部门
    /// </summary>
    public class DepartmentController : BaseSetBaseController
    {

        private readonly IDepartmentQueryService _departmentQueryService;
        private readonly IDepartmentService _departmentService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public DepartmentController(IDepartmentQueryService departmentQueryService
            ,IDepartmentService departmentService)
        {
            _departmentQueryService = departmentQueryService;
            _departmentService = departmentService;
        }


        /// <summary>
        /// 获取部门树
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<List<GetDepartmentTreeListOutput>>> GetDepartmentTreeList([FromQuery]GetDepartmentTreeListInput input)
        {
            return await _departmentQueryService.GetDepartmentTree(input);
        }

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseApiResult<GetDepartmentOutput>> GetDepartment([FromQuery]GetDepartmentInput input)
        {
            return await _departmentQueryService.GetDepartment(input);
        }

        /// <summary>
        /// 创建部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<bool>> Create(CreateDepartmentInput input)
        {
            return await _departmentService.Create(input);
        }

        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> Update(UpdateDepartmentInput input)
        {
            return await _departmentService.Update(input);
        }

        /// <summary>
        /// 更新部门-用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> UpdateDepartmentUser(UpdateUserDepartmentInput input)
        {
            return await _departmentService.UpdateDepartmentUser(input);
        }
        
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteById(SingleDeleteInput input)
        {
            return await _departmentService.DeleteById(input);
        }

        /// <summary>
        /// 删除指定的用户-部门关系
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteUserDepartment(DeleteUserDepartmentInput input)
        {
            var res = await _departmentService.DeleteUserDepartment(input);
            return res;
        }
    }
}
